/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phan.connection;

/**
 *
 * @author bailleurs services
 */
public class CheckString {
public CheckString(){

}
public Boolean CheckEmail(String email){
     boolean valide=false;
     int j=0;
     int count=0;
     int t=0;
    for (int i=0;i<email.length();i++)
        {
        if(email.charAt(i)!='@')
            count=count+1;
        if(email.charAt(i)=='@')
        { j=j+1;
          count=t;
         valide=true;

        }
        if(t>=email.length())
            valide=false;
        }
     if(j>=2||j==0)
          valide=false;
   System.out.print("valide luc nay la: "+ valide);
    return valide;
}

public Boolean CheckOver18(String year,String month,String date){
    boolean valide=false;
    
    String bd = date+"/"+month+"/"+year;
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy");
java.util.Date birthDay = null;
java.util.Date now = new java.util.Date();
try {
    birthDay = sdf.parse(bd);
    System.out.println("bd = " + birthDay);
    java.util.Calendar c1 = java.util.Calendar.getInstance();
    c1.setTime(now);
    c1.add(java.util.Calendar.YEAR, -18);
     
    if (c1.getTime().getTime() >= birthDay.getTime()) {
        System.out.println(">= than 18");
        valide=true;
    }
    else {
        System.out.println("young");
        valide=false;
    }
} catch (java.text.ParseException pe) {
    System.out.println("Error parsing date");
    valide=false;
}
 return valide;
}
public Boolean CheckOverToday(String year,String month,String date){
    boolean valide=false;

     String bd="";

     if(year.length()==4)
     {
        if(!month.equals("--mois--")&&!date.equals("--jour--"))
            bd=date+"/"+month+"/"+year;
     }

if(!bd.equals("")){
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yyyy");
java.util.Date birthDay = null;
java.util.Date now = new java.util.Date();
try {
    birthDay = sdf.parse(bd);
    System.out.println("bd = " + birthDay);
    java.util.Calendar c1 = java.util.Calendar.getInstance();
    c1.setTime(now);
    c1.add(java.util.Calendar.YEAR, 0);

    if (c1.getTime().getTime() <= birthDay.getTime()) {
        System.out.println(">= than 18");
        valide=true;
    }
    else {

        valide=false;
    }
} catch (java.text.ParseException pe) {

    valide=false;
}
}
 return valide;
}

public Boolean CheckDateFinToday(String DateFin){
    boolean valide=false;

     String bd=DateFin;



if(!bd.equals("")){
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-mm-dd");
java.util.Date Fin = null;
java.util.Date now = new java.util.Date();
try {
    Fin = sdf.parse(bd);
    System.out.println("bd = " + Fin);
    java.util.Calendar c1 = java.util.Calendar.getInstance();
    c1.setTime(now);
    c1.add(java.util.Calendar.YEAR, 0);

    if (c1.getTime().getTime() > Fin.getTime()) {
        System.out.println("stock nay bi het han roi");
        valide=true;
    }
    else {

        valide=false;
    }
} catch (java.text.ParseException pe) {

    valide=false;
}
}
 return valide;
}
public String convertDateAchat(String year,String month,String date){
    String DateSql="";

    

     if(year.length()==4)
     {
       try
       {
           int x= Integer.getInteger(year);
            if(!month.equals("--mois--")&&!date.equals("--jour--"))
            DateSql=x+"-"+month+"-"+date;
       }
        catch(Exception e){
            DateSql="1000-01-01";
        }

     }
     else DateSql="1000-01-01";

     return DateSql;
}
}
